package com.luomu.base.biz.config;

import org.apache.commons.lang3.math.NumberUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 */
@Configuration
public class RedissionConfig {

    @Value("${redis.host}")
    private String redisHost;

    @Value("${redis.port}")
    private String redisPort;

    @Value("${redis.pwd}")
    private String password;
    @Value("${redis.timeout}")
    private int timeout;

    @Bean
    public RedissonClient getRedissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://" + redisHost + ":" + redisPort)
                .setPassword(password)
                .setTimeout(timeout).setDatabase(NumberUtils.INTEGER_ONE);
        config.setCodec(new JsonJacksonCodec());
        return Redisson.create(config);
    }
}